import "package:flutter/material.dart";

// 获取文字属性
TextPainter getTextPainter(
  BuildContext context, {
  required String text,
  TextStyle? style,
  double maxWidth = double.infinity,
  int maxLines = 1,
}) {
  TextScaler textScaler = MediaQuery.of(context).textScaler;
  final TextPainter textPainter = TextPainter(
    // locale: WidgetsBinding.instance!.window.locale,//不推荐
    locale: Localizations.localeOf(context), //显示文本语言设置
    text: TextSpan(text: text, style: style), //文本内容
    textScaler: textScaler, //文本缩放因子
    maxLines: maxLines, //最大行数
    textDirection: TextDirection.ltr, //文本方向
  )..layout(maxWidth: maxWidth, minWidth: 0);
  return textPainter;
}
